package org.oos.lists;

import java.util.AbstractList;
import java.util.HashMap;
import java.util.List;

import org.oos.OOS4Java;
import org.oos.atom.entries.MultimediaEntry;
import org.oos.model.Multimedia;
import org.oos.model.OosMedia;
import org.oos.model.Review;
import org.oos.model.Site;

public class MediaList extends AbstractList<OosMedia> {

	private MultimediaList list;
	
	private HashMap<Multimedia, OosMedia> cache = new HashMap<Multimedia, OosMedia>();
	
	public MediaList(OOS4Java oos4Java, List<MultimediaEntry> list,
			Review review) {
		this.list = new MultimediaList(oos4Java, list, review);
	}
	
	public MediaList(OOS4Java oos4Java, List<MultimediaEntry> list,
			Site site) {
		this.list = new MultimediaList(oos4Java, list, site);
	}
	
	@Override
	public OosMedia get(int location) {
		Multimedia multimedia = list.get(location);
		OosMedia result = null;
		if (cache.containsKey(multimedia)) {
			result = cache.get(multimedia);
		} else {
			result = OosMedia.create(multimedia.getEntry());
			cache.put(multimedia, result);
		}
		return result;
	}

	@Override
	public int size() {
		return list.size();
	}

}
